/**
 * 1.实例化时往 Dep 中添加自己
 * 2.定义update，数据变化时dep通知watcher更新视图
 */

class Watcher {constructor(vm, key, cb) {
        this.vm = vm;
        this.key = key;
        this.cb = cb;
        Dep.target = this;
        this.oldValue = vm[key];
        Dep.target = null;
    }
    update() {
        const newValue = this.vm[this.key];
        if(newValue === this.oldValue) {
            return;
        }
        this.cb(newValue);
    }
}